package com.config;

import cn.hutool.http.ssl.CustomProtocolsSSLFactory;
import cn.hutool.http.ssl.SSLSocketFactoryBuilder;
import feign.Client;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient;
import org.springframework.cloud.openfeign.loadbalancer.OnRetryNotEnabledCondition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import sun.security.ssl.SSLSocketFactoryImpl;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

@Configuration
@EnableFeignClients
public class FeignConfig {
    @Autowired
    SSLContext sslSocketFactory;

    @Bean
    public Client feignClientforHttp() throws Exception {

        SSLSocketFactory socketFactory = sslSocketFactory.getSocketFactory();

        HostnameVerifier hostnameVerifier = new HostnameVerifier() {
            @Override
            public boolean verify(String s, SSLSession sslSession) {
                return true;
            }
        };
        return new Client.Default(socketFactory, hostnameVerifier);
    }
    @org.springframework.cloud.openfeign.FeignClient(url = "https://localhost:8083",name = "remoteTest", contextId = "feignClientforHttp")
    public interface FeignClient {
        @RequestMapping("remote")
        public String remoteSayHello();
    }
}
